import 'package:camera/camera.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:vischat/app_binding.dart';
import 'package:vischat/core/config/app_config.dart';
import 'package:vischat/generated/route_table.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'generated/translations/translations.dart';

List<CameraDescription> cameras = [];

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();

  // 坑爹的路由机制问题，把全局服务注入改到这里了
  // 不然启动页老是缺服务
  // 下面的AppBinding()保留,也可以删除
  await Get.putAsync(() async {
    final binding = AppBinding();
    binding.dependencies();
    return binding;
  }, permanent: true);

  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return ScreenUtilInit(
      designSize: const Size(720, 1280),
      builder: (_, child) {
        return MediaQuery(
          // 禁用字体缩放，将 textScaleFactor 设置为 1.0
          data: MediaQuery.of(
            context,
          ).copyWith(textScaler: const TextScaler.linear(1.0)),
          child: GetMaterialApp(
            debugShowCheckedModeBanner: false,
            title: 'Vischat',
            builder: FlutterSmartDialog.init(),
            initialBinding: AppBinding(),
            translations: AppTranslations(),
            locale: Get.deviceLocale,
            fallbackLocale: AppConfig.locales.first,
            localizationsDelegates: const [
              GlobalMaterialLocalizations.delegate, // Material组件本地化
              GlobalCupertinoLocalizations.delegate, // iOS组件本地化
              GlobalWidgetsLocalizations.delegate, // 基础组件本地化
            ],
            supportedLocales: AppConfig.locales,
            initialRoute: RouteTable.SPLASH,
            getPages: RouteTable.pages,
            theme: ThemeData(
              tabBarTheme: const TabBarTheme(dividerColor: Colors.transparent),
            ),
          ),
        );
      },
    );
  }
}
